const fs = require("fs");
const path = require("path");
const COS = require("cos-nodejs-sdk-v5");
const cos = new COS({
  SecretId: "AKID7CEJIPZrMrJkGxVUSUzu6dE1QuhVIY8z", // 推荐使用环境变量获取；用户的 SecretId，建议使用子账号密钥，授权遵循最小权限指引，降低使用风险。子账号密钥获取可参考https://cloud.tencent.com/document/product/598/37140
  SecretKey: "njDNYB28OftBKQpN8nPF4timryEUl4Rx", // 推荐使用环境变量获取；用户的 SecretKey，建议使用子账号密钥，授权遵循最小权限指引，降低使用风险。子账号密钥获取可参考https://cloud.tencent.com/document/product/598/37140
});

const sourcePath = path.join("arena-zh");
fs.existsSync(sourcePath);
if (!sourcePath) {
  fs.mkdirSync(localPath, { recursive: true });
}

fs.readdirSync(sourcePath).forEach(async (file) => {
  console.log(file);
  const Key = `assets/zh/images/cardlist/card/${file}`;
  cos.putObject(
    {
      Bucket: "uazh-1258961180", // 必须
      Region: "ap-nanjing", // 存储桶所在地域，必须字段
      Key, // 必须
      StorageClass: "STANDARD",
      Body: fs.readFileSync(path.join(sourcePath, file)),
    },
    (err) => {
      if (!err) {
        console.log(Key + " : done");
      }
    }
  );
});
